import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_common/ui/widget/swipe_layout.dart';

class SwipeDemo extends StatefulWidget {
  const SwipeDemo({Key? key}) : super(key: key);

  @override
  State<SwipeDemo> createState() => _SwipeDemoState();
}

class _SwipeDemoState extends State<SwipeDemo> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text("button demo"),
        ),
        body: body()
    );
  }

  Widget body() {
    return Column(
      children: [
        SwipeLayout(
          onClick: (context, index) {
            print("手动关闭");
            context.close();
          },
          buttons: [
            Container(
              color: Colors.red,
              alignment: Alignment.center,
              child: const Text("测试"),
            )
          ],
          child: Container(
            alignment: Alignment.center,
            color: Colors.white,
            width: double.infinity,
            height: 50,
            child: Text("单个按钮侧滑(手动关闭)"),
          ),
        ),
        SwipeLayout(
          onClick: (context, index) {
            print("点击测试${index}");
          },
          buttons: [
            Container(
              color: Colors.red,
              alignment: Alignment.center,
              child: const Text("测试1"),
            ),
            Container(
              color: Colors.green,
              alignment: Alignment.center,
              child: const Text("测试2"),
            ),
            Container(
              color: Colors.blue,
              alignment: Alignment.center,
              child: const Text("测试3"),
            ),
          ],
          singleButtonWidth: 90,
          child: Container(
            alignment: Alignment.center,
            color: Colors.white,
            width: double.infinity,
            height: 50,
            child: Text("多个按钮侧滑"),
          ),
        )
      ],
    );
  }
}
